﻿@model Century.Model.CMS.SitePage
@{
    Layout = "~/Areas/Admin/Views/Shared/_TreeLayout.cshtml";
}
@if (Model != null)
{
    <div class="detail_header">
        <h2>
            @{
    if (Model.IsHomePage)
    { 
                <text><img src="@Url.Content("/Areas/Admin/Content/themes/admin/img/general/page_default.png")" alt="Disabled Page" /></text>
    }
    else
    {
        if (!Model.IsPublished)
        { 
                <text><img src="@Url.Content("/Areas/Admin/Content/themes/admin/img/general/page_red.png")" alt="Disabled Page" /></text>
        }
    }
            }
            @(!string.IsNullOrEmpty(Model.Title) ? Model.Title : Model.LocalName)
        </h2>
        <div class="breadcrumb">
            @* @Html.Partial("_AdminBreadcrumb")*@
        </div>
    </div>
    <br />
   
    <div id="tabStrip">
        @if (Model.DraftSourcePageId <= 0)
        {
            <table>
                <tr>
                    <td>
                        <a target="_blank" onclick="EditPage();" class="btn_green btn" id="editPage">
                            <b>Edit Content</b>
                        </a>
                        <a target="_blank" onclick="PublishDraft();" class="btn_orange btn" id="publishDraft" style="display: none;">
                            <b>Publish Content</b>
                        </a>
                    </td>
                    <td>
                        <a target="_blank" class="btn_green btn" id="previewPage">Preview Page
                        </a>
                    </td>
                    <td>
                        <a target="_blank" onclick="CancelEdit();" class="btn_green btn" id="cancelEdit" style="display: none;">Cancel
                        </a>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
            </table>
        }
        @{ 
        string path = "en";//Century.Business.Repository.PersistData.CurrentSite.Path;
        string pageName = (!string.IsNullOrEmpty(Model.LocalName) ? Model.LocalName : Model.Name);
        //string draftMode = (Model.DraftSourcePageId > 0 ? "true" : "false");
        string iframeSource = string.Format("/{0}/{1}?desingmode=true&draftmode=false", path, pageName);//desingmode=true&

        Html.Telerik().TabStrip()
        .Name("PageDetailTabStrip")
        .Items(tabstrip =>
        {
            tabstrip.Add()
                .Text("Preview")
                .ImageUrl(Url.Content("~/Areas/Admin/content/themes/admin/img/tabstrip/content.png"))
                .Content(@<text><iframe id="ifrmDesign" allowtransperancy="true" class="ifrmDesign" style="height: 100%; min-height: 600px; background: url('/Areas/Admin/content/themes/admin/img/gifs/loading.gif') center no-repeat;" src='@(iframeSource)' width="100%" height="100%"></iframe></text>);

            tabstrip.Add()
                .Text("Settings")
                .ImageUrl(Url.Content("~/Areas/Admin/Content/themes/admin/img/tabstrip/settings.png"))
                .Content(Html.Action("Settings", "PageManagement", new { id = Model.Id }).ToString());

            tabstrip.Add()
                .Text("Meta")
                .ImageUrl(Url.Content("~/Areas/Admin/Content/themes/admin/img/tabstrip/page_properties.png"))
                .Content(Html.Action("Properties", "PageManagement", new { id = Model.Id }).ToString());

            tabstrip.Add()
                .Text("Advanced")
                .ImageUrl(Url.Content("~/Areas/Admin/Content/themes/admin/img/tabstrip/applications.png"))
                .Content(Html.Action("Advanced", "PageManagement", new { id = Model.Id }).ToString());

        })
        .SelectedIndex(0)
        .Render();
        }
    </div>
    @section scripts{
        <script type="text/javascript">
        @if (Model != null)
        {
            <text>
            function EditPage() {
                $("#editPage").hide();
                $("#publishDraft").show();
                $("#cancelEdit").show();
                PageOperationCall('@(Url.Action("GenerateDraftPage", "PageManagement"))', '@(Model.Id)', 'EditPage');
            }

            function CancelEdit() {
                $("#editPage").show();
                $("#publishDraft").hide();
                $("#cancelEdit").hide();
                PageOperationCall('@(Url.Action("CancelDraftPage", "PageManagement"))', '@(Model.Id)', 'CancelEdit');
                }

                function PublishDraft() {
                    $("#editPage").show();
                    $("#publishDraft").hide();
                    $("#cancelEdit").hide();
                    PageOperationCall('@(Url.Action("PublishDraftPage", "PageManagement"))', '@(Model.Id)', 'PublishDraft');
                }

                $(document).ready(function () {
                    $("#previewPage").click(function () {
                        window.open($('#ifrmDesign').attr('src'));
                    });
                });
            </text>
        }

            function PageOperationCall(urlAction, _data, _ftype) {
                try {
                    var _URL = urlAction + '/' + _data;
                    $.ajax({
                        url: _URL,
                        type: 'POST',
                        data: '',
                        contentType: 'application/json; charset=utf-8',
                        beforeSend: function () {
                            $('#ifrmDesign').css('background', 'url(/Areas/Admin/Content/themes/admin/img/gifs/loading.gif) no-repeat');
                        },
                        success: function (data) {
                            if (_ftype == 'EditPage') {
                                $("#ifrmDesign").attr('src', '/en/' + data + '?desingmode=false&draftmode=true');
                            }
                            else if (_ftype == 'CancelEdit') {
                                $("#ifrmDesign").attr('src', '/en/' + data + '?desingmode=true&draftmode=false');
                            }
                            else if (_ftype == 'PublishDraft') {
                                document.location.reload();
                            }
                        },
                        error: function () {
                            document.location.reload();
                        }
                    });
                } catch (e) {
                    return false;
                }
            }
        </script>
        
      
    }
}
else
{
    <!-- Site management tabs start -->
    @Html.Partial("~/Areas/Admin/Views/SiteManagement/SiteManagementTabs.cshtml")
    <!-- Site management tabs end -->
}

